package com.franklin.java.ui;

import com.franklin.java.api.ui.jpanel.AbstractComponent;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentManager;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.Optional;


/**
 * 抽象ToolWindow内容窗口，对idea窗口内容包装
 * @author Franklin
 * @since 2021/9/26 9:48
 */
public abstract class ToolWindowContent extends AbstractComponent{

    /**
     * 窗口内容
     */
    protected Content content;

    public boolean isVisible() {
        return Optional.ofNullable(content.getManager())
            .map(contentManager -> contentManager.findContent(this.content.getDisplayName()))
            .isPresent();
    }

    public Content getContent() {
        return content;
    }

    /**
     * must call this.content = createContent(); at subclass's constructor<br>
     * @author Franklin
     * @since 2021/9/26 11:13
     * @param :
     * @return com.intellij.ui.content.Content
     */
    @NotNull
    protected abstract Content createContent();
}
